// 多语言配置文件
// Hawkpass 密码生成器国际化支持

const i18n = {
  // 中文（简体）
  'zh-CN': {
    // 菜单
    menu: {
      app: 'Hawkpass',
      about: '关于 Hawkpass',
      quit: '退出',
      edit: '编辑',
      undo: '撤销',
      redo: '重做',
      cut: '剪切',
      copy: '复制',
      paste: '粘贴',
      selectAll: '全选',
      view: '视图',
      reload: '重新加载',
      forceReload: '强制重新加载',
      toggleDevTools: '切换开发者工具',
      resetZoom: '实际大小',
      zoomIn: '放大',
      zoomOut: '缩小',
      toggleFullscreen: '切换全屏',
      window: '窗口',
      minimize: '最小化',
      zoom: '缩放',
      maximize: '最大化',
      close: '关闭窗口',
      help: '帮助',
      repository: '项目仓库',
      originalHawkpass: '原版 Hawkpass',
      reportIssue: '报告问题',
      dicewareGuide: 'Diceware 密码指南',
      language: '语言',
      chineseSimplified: '简体中文',
      english: 'English',
    },
    // 关于对话框
    about: {
      title: '关于 Hawkpass',
      description: '密码生成器 on HarmonyOS',
      version: '版本',
      based: '基于 Diceware 的安全密码生成',
    },
    // 窗口标题
    window: {
      title: 'Hawkpass - 密码生成器',
    },
  },

  // 英语
  'en-US': {
    // Menu
    menu: {
      app: 'Hawkpass',
      about: 'About Hawkpass',
      quit: 'Quit',
      edit: 'Edit',
      undo: 'Undo',
      redo: 'Redo',
      cut: 'Cut',
      copy: 'Copy',
      paste: 'Paste',
      selectAll: 'Select All',
      view: 'View',
      reload: 'Reload',
      forceReload: 'Force Reload',
      toggleDevTools: 'Toggle Developer Tools',
      resetZoom: 'Actual Size',
      zoomIn: 'Zoom In',
      zoomOut: 'Zoom Out',
      toggleFullscreen: 'Toggle Full Screen',
      window: 'Window',
      minimize: 'Minimize',
      zoom: 'Zoom',
      maximize: 'Maximize',
      close: 'Close Window',
      help: 'Help',
      repository: 'Repository',
      originalHawkpass: 'Original Hawkpass',
      reportIssue: 'Report Issue',
      dicewareGuide: 'Diceware Guide',
      language: 'Language',
      chineseSimplified: '简体中文',
      english: 'English',
    },
    // About dialog
    about: {
      title: 'About Hawkpass',
      description: 'Password Generator on HarmonyOS',
      version: 'Version',
      based: 'Secure password generation based on Diceware',
    },
    // Window title
    window: {
      title: 'Hawkpass - Password Generator',
    },
  },
};

// 默认语言：中文
let currentLocale = 'zh-CN';

// 获取翻译
function t(key) {
  const keys = key.split('.');
  let value = i18n[currentLocale];
  
  for (const k of keys) {
    if (value && typeof value === 'object') {
      value = value[k];
    } else {
      return key; // 如果找不到翻译，返回 key
    }
  }
  
  return value || key;
}

// 设置语言
function setLocale(locale) {
  if (i18n[locale]) {
    currentLocale = locale;
    return true;
  }
  return false;
}

// 获取当前语言
function getLocale() {
  return currentLocale;
}

// 获取所有支持的语言
function getSupportedLocales() {
  return Object.keys(i18n);
}

module.exports = {
  t,
  setLocale,
  getLocale,
  getSupportedLocales,
  i18n,
};

